<template>
  <div class="brand-wrapper">
    <div class="brand-content">
      <topic-header name="合作数商" en-name="Brand merchants" @change="changeIndex"
                    :active-index="activeIndex"
                    :length="computedLength"></topic-header>
      <div class="brand-item-wrapper">
        <div class="brand-item" v-for="(item,index) in brandList" :key="item.supplierId">
          <img :src="item.logoUrl"/>
          <div class="brand-name" @click="toList(item.supplierId)">{{ item.supplierName }}</div>
          <div class="brand-desc">{{ item.introduction }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import TopicHeader from './TopicHeader'
import {qryBrandSupplierList} from '@/api/portal'

export default {
  name: 'Brand',
  components: {
    TopicHeader
  },
  data () {
    return {
      brandList: [],
      activeIndex: 0,
      params: {
        page: 1,
        limit: 10
      },
      computedLength: 1
    }
  },
  computed: {
    // displayList () {
    //   return this.brandList.slice(this.activeIndex * 10, (this.activeIndex + 1) * 10)
    // },
    // computedLength () {
    //   return Math.ceil(this.brandList.length / 10)
    // }
  },
  created () {
    this.loadData()
  },
  methods: {
    loadData () {
      qryBrandSupplierList(this.params).then(res => {
        if (res.code === 0) {
          this.brandList = res.data.records
          this.computedLength = Number(res.data.pages) || 1
        }
      })
    },
    changeIndex (index) {
      if (this.activeIndex === index) return
      this.activeIndex = index
      this.params.page = this.activeIndex + 1
      this.loadData()
    },
    toList(id){
      this.$emit('list',id)
    }
  }
}
</script>

<style scoped lang="scss">
$mainColor: #3370FF;
.brand-wrapper {
  width: 100%;
  background-image: linear-gradient(to right, #EAF5FF, #FCFDFF);
  height: 420px;
  padding: 40px 0;
}

.brand-content {
  width: 1200px;
  margin: auto;
}

.brand-item-wrapper {
  display: flex;
  align-items: center;
  flex-wrap: wrap;

  .brand-item {
    width: calc((100% - 80px) / 5);
    margin-left: 20px;
    height: 140px;
    background: #FFFFFF;
    border: 1px solid #E2E2E2;
    border-radius: 10px;
    padding-top: 22px;
    padding-bottom: 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    transition: transform .1s;

    &:hover {
      border-color: transparent;
      transform: translateY(-2px);
      box-shadow: 0px 0px 10px 0px rgba(0, 120, 254, 0.1);
    }

    img {
      width: 164px;
      height: 40px;
    }

    .brand-name {
      padding: 0 20px;
      cursor: pointer;
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC, sans-serif;
      font-weight: 500;
      color: #323232;
      text-align: center;
      line-height: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 100%;

      &:hover {
        color: $mainColor;
      }
    }

    .brand-desc {
      padding: 0 20px;
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC, sans-serif;
      font-weight: 400;
      color: #909090;
      line-height: 12px;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    &:nth-child(5n+1) {
      margin-left: 0;
    }

  }
}
</style>
